import React from 'react';
import {
    Row,
    Col,
    Table,
} from 'antd';
import axios from 'axios';
import intercept from '../../utils/intercept';
import { config } from 'utils';
import './less/common.less'


export default class ActivityRecords extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            dataSource: [],
            loading: false,
            pagination: {
                current: 1,
                pageSize: 10
            },
            onChange: this.onChange,
            keyword: 0,
        };
    };
    componentDidMount() {
        this.getActivitys({ page: 1 });
    };
    search(value) {
        this.setState({ keyword: value });
        this.getActivitys({ keyword: value });
    }
    onChange = (pagination, filters, sorter) => {
        this.getOrderInfo({
            sortField: sorter.field,
            sortOrder: sorter.order,
            page: pagination.current,
            keyword: this.state.keyword,
            ...filters
        });
    };
    getActivitys = (params = {}) => {
        const token = sessionStorage.getItem("token");
        this.setState({ loading: true });
        var keyword = typeof (params.keyword) === "undefined"
            ? ''
            : params.keyword;
        axios
            .get(`${config.api}Marketing/GetActivityRecords?page=${params.page}&pageSize=${this.state.pagination.pageSize}&activityid=${keyword}`, { headers: { Authorization: 'Bearer ' + token } })
            .then((data) => {
                const pagination = {
                    ...this.state.pagination
                };
                //console.log(data);
                pagination.total = data.data.pageList.totalRows;
                pagination.current = params.page;
                this.setState({ loading: false, dataSource: data.data.pageList.collections, pagination });

            })
            .catch(err => {
                intercept;
            })
    }
    render() {
        const scroll = {
            y: 600
        };
        const columns = [
            {
                title: '活动名称',
                dataIndex: 'activityName',
                width: 150
            },
            {
                title: '订单号',
                dataIndex: 'orderCode',
                width: 150
            },
            {
                title: '用户ID',
                dataIndex: 'userId',
                width: 150
            },
            {
                title: '订单金额',
                dataIndex: 'orderAmount',
                width: 150
            },
            {
                title: '优惠金额',
                dataIndex: 'discountAmount',
                width: 150
            },
            {
                title: '优惠时间',
                dataIndex: 'orderTime',
                width: 150
            }
        ];
        return (
            <div>
                <div className="orderinfo">
                    <Row gutter={8} style={{
                        marginTop: '20px'
                    }}>
                        <Col span={24}>
                            <Table
                                {...this.state}
                                bordered={true}
                                columns={columns}
                                scroll={scroll} />
                        </Col>
                    </Row>
                </div>
            </div>
        )
    }
}